export default {
  data() {
    return {
      $scrollPositions: new Map(),
    };
  },
  methods: {
    $scrollToBottom(containerRefName) {
      this.$nextTick(() => {
        // 首先尝试找到实际的滚动容器 - el-main
        const scrollContainer = this.$el?.closest('.el-main');
        if (scrollContainer) {
          scrollContainer.scrollTop = scrollContainer.scrollHeight;
          return;
        }
        
        // 备用方案：使用原来的逻辑
        const el = this.$refs[containerRefName];
        if (!el) return;
        el.scrollTop = el.scrollHeight;
      });
    },

    $rememberScroll(containerRefName) {
      const el = this.$refs[containerRefName];
      if (!el) return;
      this.$scrollPositions.set(containerRefName, el.scrollTop);
    },

    $restoreScroll(containerRefName) {
      const el = this.$refs[containerRefName];
      if (!el) return;
      const top = this.$scrollPositions.get(containerRefName) || 0;
      this.$nextTick(() => {
        el.scrollTop = top;
      });
    },
  },
};
